using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BlackBird : Bird
{
    private List<Pig> pigs = new List<Pig> ();
    public override void ShowSkill()
    {
        base.ShowSkill();
        if(pigs.Count > 0&&pigs!=null)
        {
            for(int i = 0; i < pigs.Count; i++)
            {
                pigs[i].Dead();
            }
        }
        OnClear();
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.transform.tag=="Enemy")
        {
            pigs.Add(collision.transform.GetComponent<Pig>());
        }
    }

    private void OnTriggerExit2D(Collider2D collision)
    {
        if(collision.gameObject.tag=="Enemy")
        {
            pigs.Remove(collision.gameObject.GetComponent<Pig>()); 
        }
    }

    public void OnClear()
    {
        rg.velocity = Vector3.zero;
        Instantiate(boom, transform.position, Quaternion.identity);
        spr.enabled = false;
        GetComponent<CircleCollider2D>().enabled = false;
        trail.heroIdle();
    }

    protected override void Next()
    {
        ShowSkill();
        GameManager.instance.birds.Remove(this);
        if (GameManager.instance.birds.Count > 0 && GameManager.instance.pigs.Count > 0)
        {
            right.enabled = true;
            left.enabled = true;
        }
        Destroy(gameObject);
        GameManager.instance.NextBird();
    }
}
